# 多无人机 4宽x8高x32台 刚好覆盖场地

from utils import *

clear()

l = 32

def do_task(t):
    x0,y0,ismain = t
    def action(x,y):
        map.append((x,y))
        if get_ground_type() != Grounds.Soil:
            till()
        plant(Entities.Pumpkin)
        pourwater(.25)
    map = []
    snake_traverse(l,x0,y0,x0+4-1,y0+8-1,action)
    round = 0
    while 1:
        round += 1
        growing_map = []
        for pos in map:
            goto(l,pos[0],pos[1])
            if not can_harvest():
                plant(Entities.Pumpkin)
                growing_map.append(pos)
                if round > 2:
                    pourwater(.75)
                    # use_item(Items.Fertilizer)
                
        map = growing_map
        if len(map) == 0:
            if not ismain:
                return
            while 1:
                if num_drones() == 1:
                    harvest()
                    return

while 1:
    for y in range(4):
        for x in range(8):
            if x == 0 and y == 0:
                continue
            spawn_drone(create_task(do_task, (x*4,y*8,None)))
    do_task((0,0,True))
